<?php if (!defined('__ACCESS__')) exit; ?> 
        <script type="text/javascript" src="<?php $this->path('js/selectBox.js');?>"></script>
        <script type="text/javascript" src="<?php $this->path('js/ui/ui.dialog.js');?>"></script>
		<script type="text/javascript" src="<?php $this->path('js/jquery.cleditor.js');?>"></script>
		<script type="text/javascript" src="<?php $this->path('js/validate.js');?>"></script>
		
		<script type="text/javascript" src="<?php $this->path('js/jquery.dlmenu.js');?>"></script>
        <link href="<?php $this->path('css/ui.dialog.css');?>" rel="stylesheet" media="all" />
		<link href="<?php $this->path('css/component.css');?>" rel="stylesheet" media="all" />
		<section id="main" class="entire_width" style="margin:-10px;">
    		<div class="container_12">     
        		<?php $this->getPageCrumb(); ?> 
        		<div id="content" class="grid_9" style="min-height:600px;width:100%">
        			<h1 class="page_title">Product List</h1>
        	      
        			<div class="options" style="background:#fff;z-index: 1;">
        				<div class="grid-list">
        					<a class="grid curent"><span>img</span></a>
        					<a class="list"><span>img</span></a>
        				</div><!-- .grid-list -->
        				<div class="show">
        					<span>Show</span>
        					<select title="Show">
        						<option>500</option>
        						<option>1000</option>
        						<option>1500</option>
        						<option>2000</option>
        						<option>10000</option>
        					</select>
        			    	<span class="per-page">per page</span>
        				</div><!-- .show -->
        		     
        				<div class="sort">
        					<span class="sort-by">Sort By</span>
        					<select title="Sort">
        						<option value="iname">Item</option>
        						<option value="cname">Category</option>
        						<option value="retail_price">Retail Price</option>
        						<option value="whole_sale_price">Wholesale Price</option>
        						<option value="stock">Stock</option>
        					</select>
        			    
        					<a class="sort_up" flag="1">&#8595;</a>
        				</div><!-- .sort -->
						
						<div class="search-bar" style="z-index: 10;position: relative;">
							<input id="item-search" type="text" placeholder="Search for Item" style="width:300px;">
						</div>
				<div id="dl-menu" class="dl-menuwrapper demo-2" style="z-index: 1;margin-top: -40px;margin-left: 10px;">
				<button class="dl-trigger ease" title="Open Menu">Open Menu</button>
				<ul class="dl-menu">
					<li>
						<a href="#">Item</a>
						<ul class="dl-submenu">
							<li><a href="#" id="new-item" class="no-ease">New Item</a></li>
    						<li><a href="#" id="del-item"  class="no-ease">Delete Item</a></li>
    						<li><a href="#" id="category"  class="no-ease">Manage Category</a></li>
						</ul>
					</li>
					<li>
						<a href="#">Supplier</a>
						<ul class="dl-submenu">
    						<li><a href="#" id="reorder-list"  class="no-ease">Delivery</a></li>
    						<li><a href="#" id="reorder-item"  class="no-ease">Order Stock</a></li>
    						<li><a href="#" id="supplier"  class="no-ease">Manage Supplier</a></li>
						</ul>
					</li>
					<li>
						<a href="#">Others</a>
						<ul class="dl-submenu">
    						<li><a href="#" class="no-ease">Print Barcode</a></li>
    						<li><a href="#" id="import-item"class="no-ease">CVS Import</a></li>
    						<li><a href="#" class="no-ease">CVS Export</a></li>
						</ul>
					</li>
				</ul>
			</div><!-- /dl-menuwrapper -->
        			</div><!-- .options -->
					<div id="renderer"></div>				
        			<div class="clear"></div>
        		</div><!-- #content -->				
        		<!--<div id="sidebar" class="grid_3">
        			<aside id="categories_nav">
        				<h3>Categories</h3>
    		     
        				<nav class="left_menu">
        					<ul>
        						<li><a href="#" class="no-ease">Papers <span>(21)</span></a></li>
        						<li><a href="#" class="no-ease">Ballpen <span> (27)</span></a></li>
        						<li class="last current"><a href="#">Other <span>(135)</span></a></li>
        					</ul>
        				</nav><!- .left_menu 
    				</aside><!-#categories_nav 
    			</div> # sidebar -->
    		</section>
    		<div class="clear"></div>


					
    		</div><!-- .container_12 -->
			<div id="dialog-form" title="Add New Item">
			<?php //$this->render2(CP_BAS . 'pos/inventory/add/index.php'); ?>
			</div>
			<div id="dialog-form-all" title="Title"></div>
		<script>
			$.ajaxSetup({
				type: 'POST',
				headers: { "cache-control": "no-cache" }
			});
			var max_display = 500;
			var sort_by = 'iname';
			var view_by = 0;
			var sort_with = 1;
			
			//$('#block_nav_primary .container_12').hide();
			//$('#branding').children().hide();
			$('#branding #site_logo').parent().parent().css('margin-top','-40px').show();
			$('#branding #cart_nav').hide();
			$('#block_nav_primary').css('background', '#f5f7f9');
			$('#branding .grid_3 .search').hide();
			$('#branding .private ul').children().hide();
			$('#branding .private ul li:nth-child(5)').show();
			$('#branding .private ul li:nth-child(6)').show();
			$('#branding .private ul li:last-child').show().parent().parent().css({"margin-right": "-260px", "margin-top": "-5px"}).parent().css('height','10px');
			$('header#branding').css('height','50px');
			$('.phone_top').parent().css('visibility','hidden');
			//View select
    		$('select').selectBox().change( function() {
   				var value = $(this).val();
				switch($(this).attr('title')){
					case "Show":
						max_display = value;
						reload_listing();
						break;
					case "Sort":
						switch( value ){
							case "Item":
								value = "iname";
								break;
							case "Price":
								value = "unit_price";
								break;
							case "Mark Up":
								value = "mark_up";
								break;
						}
						sort_by = value.toLowerCase();
						reload_listing();
						break;
					default:
						alert("Not Implemented!");
				}
			});
			var reload_listing = function(){
				reload_listing(0);
			}
			var reload_listing = function(id){
				var keyword = $('#item-search').val();
    			$('#renderer').html('<div id="load"><img src="<?php $this->path('img/loading.gif');?>" /></div>');
    			$.post('?module=pos&action=inventory&action2=list&ajax=true', {view:view_by, display:max_display, sort_by:sort_by, sort_with:sort_with, key:keyword, idkey:id}, function(data) {
    				$('#renderer').hide().fadeIn('slow').html(data);
					img_fix();
					//$(".ellipsis").ellipsis();
    			});
			};
			var set_listing = function(data){
    			$('#renderer').html('<div id="load"><img src="<?php $this->path('img/loading.gif');?>" /></div>');
    			$('#renderer').hide().fadeIn('slow').html(data);
				img_fix();
				//$(".ellipsis").ellipsis();
			};
			reload_listing();
			$('.grid-list a').click(function(){
				view_by = ($(this).hasClass('grid')?0:1);
				reload_listing();
				if(!$(this).hasClass('curent'))
					$(this).parent().children().toggleClass('curent');
			});
			$('.sort_up').click(function(){
				if($(this).attr('flag') == 0){
					$(this).html('&#8595;');
					$(this).attr('flag', 1);
					sort_with = 1;
				}else{
					$(this).html('&#8593;');
					$(this).attr('flag', 0);
					sort_with = 0;
				}
				reload_listing();
			});
			$('#new-item').click(function(e){
				e.preventDefault();
				$.get('?module=pos&action=inventory&action2=add&ajax=true', function(data) {
					$('#dialog-form').dialog('open');
					$('#dialog-form').html(data);
					/*$("#editor").cleditor({
						controls:"undo redo | bold italic underline strikethrough subscript superscript | color removeformat | bullets numbering | outdent indent | alignleft center alignright justify | link unlink | cut copy paste"
					});*/	
					$('.ui-dialog .ui-dialog-content').css('overflow','auto').scrollTop(0);
					$('.ui-dialog').css('top',($('body').scrollTop()+10) + 'px');
				});
				return false;
			});
			$('#category').click(function(e){
				e.preventDefault();
				id = getSelected(false);
				$.post('?module=pos&action=inventory&action2=category&ajax=true', {id:id,list:1}, function(data) {
    				$('#dialog-form-all').html(data);
					$('#dialog-form-all').dialog({
      					height: 600,
      					width: 600,
      					modal: true,
						resizable: false
					});
					$('#ui-dialog-title-dialog-form-all').html('New Category').parent().parent().css('overflow','hidden');
					$('#dialog-form-all').dialog('open');
    			});
				return false;
			});
			$('#supplier').click(function(e){
				e.preventDefault();
				id = getSelected(false);
				$.post('?module=pos&action=inventory&action2=supplier&ajax=true', {id:id,list:1}, function(data) {
    				$('#dialog-form-all').html(data);
					$('#dialog-form-all').dialog({
      					height: 500,
      					width: 800,
      					modal: true,
						resizable: false
					});
					$('#ui-dialog-title-dialog-form-all').html('Manage Supplier').parent().parent().css('overflow','hidden');
					$('#dialog-form-all').dialog('open');
    			});
				return false;
			});
			$('#import-item').click(function(e){
				e.preventDefault();
				$.post('?module=pos&action=inventory&action2=add&page=import&ajax=true', function(data) {
    				$('#dialog-form-all').html(data);
					$('#dialog-form-all').dialog({
      					height: 300,
      					width: 400,
      					modal: true,
						resizable: false
					});
					$('#ui-dialog-title-dialog-form-all').html('Import').parent().parent().css('overflow','hidden');
					$('#dialog-form-all').dialog('open');
    			});
				return false;
			});
			var refunc_items = function(){
    			$('#reorder-item,.reorder-item').click(function(e){
    				e.preventDefault();
					if ($('#item_preview').dialog('isOpen')===true)
						$('#dialog-form-all').dialog('close');
					if((id=$(this).attr('iid')) === undefined)
						id = 0;
    				$.post('?module=pos&action=inventory&action2=reorder&ajax=true', {id:id,list:2}, function(data) {
        				$('#dialog-form-all').html(data);
    					$('#dialog-form-all').dialog({
          					height: 600,
          					width: 700,
          					modal: true,
    						resizable: false
    					});
    					$('#ui-dialog-title-dialog-form-all').html('New Stock Order').parent().parent().css('overflow','hidden');
    					$('#dialog-form-all').dialog('open');
        			});
    				return false;
    			});
    			$('#reorder-list, .reorder-list').click(function(e){
    				e.preventDefault();
					if ($('#item_preview').dialog('isOpen')===true)
						$('#dialog-form-all').dialog('close');
    				$.post('?module=pos&action=inventory&action2=reorder&ajax=true&page=receive&list=1', function(data) {
        				$('#dialog-form-all').html(data);
    					$('#dialog-form-all').dialog({
          					height: 400,
          					width: 800,
          					modal: true,
    						resizable: false
    					});
    					$('#ui-dialog-title-dialog-form-all').html('Delivery List').parent().parent().css('overflow','hidden');
    					$('#dialog-form-all').dialog('open');
        			});
    				return false;
    			});
				$('.del-item').each(function(){
    					if($(this).attr('click') != 1){
        					$(this).attr('click', 1);
            				$(this).click(function(e){
                    			e.preventDefault();
                				id = $(this).attr('iid');
              					if(id){
                      				if(confirm('Do you want to delete this item?'))
                      				{
              							$.post('?module=pos&action=inventory&action2=edit&page=delete&ajax=true',{id:id}, function(data) {reload_listing();});
                  						var name = $(this).parent().parent().parent().parent().next().attr('iname');
                  						set_notif('success',  '<strong>' + name + '</strong> has successfully deleted.', '', 0);
                      				}
              					}
            				});
    					}
    				});    		
				if($('#del-item').attr('click') != 1){
					$('#del-item').attr('click', 1);
        			$('#del-item').click(function(e){
        				e.preventDefault();
    					count = 0;
    					$('#list-item').find('input[type=checkbox]').each(function(){
    						if($(this).is(':checked') && $(this).parent().parent().parent().attr('id')){
    							count++;
    						}
    					});
    					if(!count && !id)
    							return;
    					if(count > 0 || id){
            				if(confirm('Do you want to delete this item/s?'))
            				{
                					$('#list-item').find('input[type=checkbox]').each(function(){
                						if($(this).is(':checked') && $(this).parent().parent().parent().attr('id')){
                							id = $(this).parent().parent().parent().attr('id');
                							$.post('?module=pos&action=inventory&action2=edit&page=delete&ajax=true',{id:id}, function(data) {reload_listing();});
                						}
                					});
        						//var name = $(this).parent().parent().parent().parent().next().attr('iname');
        						set_notif('success',  'Item/s has successfully deleted.', '', 0);
            				}
    					}
        			});
							
				}
    			$('#edit-item, .edit-item').click(function(e){
    				e.preventDefault();
					if((id=$(this).attr('iid')) === undefined)
						id=getSelected(true);
    				if(id){
        				$.post('?module=pos&action=inventory&action2=edit&ajax=true&id=' + id, function(data) {
            				$('#dialog-form-all').html(data);
        					img_fix();
        					$('#dialog-form-all').dialog({
              					height: 630,
              					width: 800,
              					modal: true,
        						resizable: false
        					});
        					$('#ui-dialog-title-dialog-form-all').html('Edit Item').parent().parent().css('overflow','hidden');
        					$('#dialog-form-all').dialog('open');
            			});
					}
    				return false;
    			});
			};
			refunc_items();
			$('#dialog-form-all').bind('dialogclose', function(event) {
				$('#dialog-form-all').html("");
 			});
			$('#dialog-form').dialog({
				autoOpen: false,
      			height: 600,
      			width: 650,
      			modal: true,
				resizable: false,
            	hide: {
                    effect: "fade",
                    duration: 400
                }
			});
			$('#dialog-form-all').dialog({
				autoOpen: false,
            	hide: {
                    effect: "fade",
                    duration: 400
                }
			});
			
			var getSelected = function(flag){
				var count = 0;
				var id = 0;
				$('#list-item').find('input[type=checkbox]').each(function(){
					if($(this).is(':checked') && $(this).parent().parent().parent().attr('id')){
						id = $(this).parent().parent().parent().attr('id');
						count++;
					}
				});
				if( !count && flag ){
					alert("No item selected");
					return 0;
				}
				return id;
			};
			
			$('#item-search').keyup(function(){
  				delay(function(){reload_listing()}, 500);
			});
			
			$('#header-top').hide().parent().css('padding-top','10px');

			$(function() {
				$( '#dl-menu' ).dlmenu({
					animationClasses : { classin : 'dl-animate-in-2', classout : 'dl-animate-out-2' }
				});
			});
			$(document).ready(function(){
				$(window).scroll(function(){
					if($(this).scrollTop()>=128){
						$('.options').css('position','fixed').css('top','0px').css('width','1063px');
    				}else{
						$('.options').css('position','relative');
					}
				});
	
			<?php 
				switch($this->get('trans')){
					case 'reorder':
						if ($this->get('keyid') != 0 && $this->get('keyid') != ''){
			?>
    			$.post('?module=pos&action=inventory&action2=reorder&ajax=true', {id:<?php echo $this->get('keyid'); ?>,list:2}, function(data) {
      				$('#dialog-form-all').html(data);
  					$('#dialog-form-all').dialog({
        					height: 600,
        					width: 700,
        					modal: true,
  						resizable: false
  					});
  					$('#ui-dialog-title-dialog-form-all').html('New Stock Order').parent().parent().css('overflow','hidden');
  					$('#dialog-form-all').dialog('open');
      			});
				<?php 
						}
						break;
					case 'edit':
						break;
					case 'new':
						break;
					case 'supedit':
						break;
					case 'catedit':
						break;
				} 
				?>
			});
		</script>